
/**
 * 深拷贝
 * @param  {...any} arg 
 * @returns 
 */
export const deepCloneXDC = (...arg) => {
    var options, name, src, copy, copyIsArray, clone,
        target = arg[0] || {},
        i = 1,
        length = arg.length,
        deep = false;
    if (typeof target === "boolean") {
        deep = target;
        target = arg[1] || {};
        i = 2;
    }
    if (typeof target !== "object" && type(target) !== "function") {
        target = {};
    }

    if (length === i) {
        target = this;
        --i;
    }

    for (; i < length; i++) {
        if ((options = arg[i]) != null) {
            for (name in options) {
                src = target[name];
                copy = options[name];

                if (target === copy) {
                    continue;
                }

                if (deep && copy && (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
                    if (copyIsArray) {
                        copyIsArray = false;
                        clone = src && Array.isArray(src) ? src : [];

                    } else {
                        clone = src && isPlainObject(src) ? src : {};
                    }
                    target[name] = deepCloneXDC(deep, clone, copy);
                } else if (copy !== undefined) {
                    target[name] = copy;
                }
            }
        }
    }
    return target;
};

const deepCopy = (obj) => {
    return JSON.parse(JSON.stringify(obj))
}

export {
    deepCloneXDC,
    deepCopy
}